package com.yc.cloud.admin.controller;

import com.yc.cloud.common.basic.api.ResponseResult;
import com.yc.cloud.admin.dto.request.SipDeviceQueryReqDTO;
import com.yc.cloud.admin.service.SipServerService;
import com.yc.cloud.admin.vo.SipDeviceListVo;
import com.yc.cloud.admin.vo.SipDeviceVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * SIP信令服务器对接控制器
 * 
 * <p>
 * 提供与SIP信令服务器的接口对接功能，包括设备查询等操作，
 * 支持GB28181等标准协议的视频监控设备管理
 * </p>
 *
 * @author kinggu
 * @since 2025-09-09
 */
@Slf4j
@RestController
@Tag(name = "SIP信令服务器对接")
@RequestMapping("/sip-server")
public class SipServerController {

    @Resource
    private SipServerService sipServerService;

    @Operation(summary = "查询SIP设备在线列表")
    @GetMapping("/devices")
    public ResponseResult<SipDeviceListVo> queryDevices(@Validated SipDeviceQueryReqDTO queryReqDTO) {
        try {
            SipDeviceListVo deviceList = sipServerService.queryDevices(queryReqDTO);
            return ResponseResult.success(deviceList);
        } catch (Exception e) {
            log.error("查询SIP设备列表失败", e);
            return ResponseResult.failed("查询设备列表失败");
        }
    }

    @Operation(summary = "根据设备ID获取SIP设备详情")
    @GetMapping("/devices/{deviceId}")
    public ResponseResult<SipDeviceVo> getDeviceById(
            @PathVariable("deviceId") @Parameter(description = "设备ID") String deviceId) {
        try {
            SipDeviceVo device = sipServerService.getDeviceById(deviceId);
            if (device != null) {
                return ResponseResult.success(device);
            } else {
                return ResponseResult.failed("设备不存在");
            }
        } catch (Exception e) {
            log.error("查询SIP设备详情失败: deviceId={}", deviceId, e);
            return ResponseResult.failed("查询设备详情失败");
        }
    }

}